import java.util.ArrayList;

public class Cart {
	
	private ArrayList<Product> products = new ArrayList<Product>(); 

	public void addProduct(Product product) {
		products.add(product);
	}

	public double getTotal() {
		double total = 0;
		double discount = 0;
		for (Product p : products) {
			total += p.getPrice();
			if ("Ubuntu".equals(p.getName())) {
				discount = Math.max(discount, 15);
			} else if ("Fedora".equals(p.getName())) {
				discount = Math.max(discount, 12);
			} else if ("Win7".equals(p.getName())) {
				discount = Math.max(discount, 10);
			}
		}
		
		return total*(100-discount)/100.0;
	}

	public void removeProduct(String name) {
		for (Product p : products)
		{
			if (name.equals(p.getName()))
			{
				products.remove(p);
				break;
			}
		}
	}

	public void removeProduct(Product p) {
		if (products.contains(p))
			products.remove(p);
	}

}
